Home Assistant 自动化实践(一)

您所在的位置:网站首页 tip-off platform Home Assistant 自动化实践(一)

Home Assistant 自动化实践(一)

#Home Assistant 自动化实践(一)| 来源: 网络整理| 查看: 265

回家开灯这件小事,我把它做复杂了

本文想探讨的是如何只使用 HomeAssistant 本身的组件来实现一个“对用户友好”的功能开关。

从一个原本应该很简单的例子讲起:我希望回家开门时玄关的灯会自动打开,并且稍后自动关闭。

对“家人”友好的需求分析

家里有你一个 geek 就足够了,你家领导只想要享受,所以开关灯的这个需求还要继续细化:

开门自动开灯,这个是最基础的。定时关灯,这也是最基础的人还在门口时候别关啊,不然多尴尬。自动开关灯虽然智能,但也不能总是无脑执行,总有需要关闭的时候,需要给一个前端开关的功能。关灯的延时长短也需要可以直接调整,领导可不会来修改你的代码和配置不仅是开门后的开灯需要自动关闭。而我手动打开灯后,也希望可以自动关闭,让我尽量忘了关灯这件事功能分解

要完成如上需求,我需要在 HA 中接入一些设备,例如

玄关灯,使用小米的单火墙壁开关控制大门上安装门窗传感器玄关合适位置放置小米人体传感器

硬件准备完毕后,开始配置 HA,首先抽象出一个“控制面板”,对于开关灯这件小事,我觉得三个控制开关就足够了:自动开灯,自动关灯,以及自动关灯的延时时间设置。有了控制面板后,我还需要新增以下几个组件:

计时器(Timer),倒计时用自动化脚本,开门时打开玄关灯自动化脚本,玄关灯打开时或者人体感应有人时开始倒计时自动化脚本,计时结束后根据当前人体感应是否有人来决策是否关灯HomeAssistant 效果

参考配置timer: hallway_light_autoclose_timer: duration: "00:01:00" input_boolean: hallway_light_auto_close: name: 门厅灯自动关闭 hallway_light_auto_turn_on: name: 门厅灯自动打开 input_number: hallway_light_turn_off_delay: name: 玄关灯延时关闭(秒) mode: box min: 1 max: 600 step: 1 group: hallway_panel: view: yes name: 玄关 entities: - group.hallway_light_settings - group.hallway_light_components hallway_lights: entities: - switch.wall_switch_left_158d000211763b - switch.wall_switch_right_158d000211763b hallway_light_settings: name: 门厅灯设置 entities: - input_boolean.hallway_light_auto_turn_on - input_boolean.hallway_light_auto_close - input_number.hallway_light_turn_off_delay hallway_light_components: - switch.wall_switch_left_158d000211763b - switch.wall_switch_right_158d000211763b - timer.hallway_light_autoclose_timer - sensor.illumination_34ce008143ab - binary_sensor.door_window_sensor_158d0001191793 - binary_sensor.motion_sensor_158d0001296340 - automation.hallway_light_auto_turn_on - automation.hallway_light_set_auto_close_timer - automation.hallway_light_timer_finish automation: - action: - data: entity_id: - group.hallway_lights service: switch.turn_on alias: hallway_light_auto_turn_on condition: - condition: state entity_id: input_boolean.hallway_light_auto_turn_on state: "on" id: '1519212408800' trigger: - entity_id: binary_sensor.door_window_sensor_158d0001191793 from: 'off' platform: state to: 'on' - alias: hallway_light_set_auto_close_timer trigger: - platform: state entity_id: binary_sensor.motion_sensor_158d0001296340 to: "off" - platform: state entity_id: group.hallway_lights to: "on" condition: - condition: state entity_id: input_boolean.hallway_light_auto_close state: "on" - condition: state entity_id: group.hallway_lights state: "on" action: service: timer.start data_template: entity_id: timer.hallway_light_autoclose_timer duration: "{{ states('input_number.hallway_light_turn_off_delay')|int }}" - alias: hallway_light_timer_finish trigger: - platform: event event_type: timer.finished event_data: entity_id: timer.hallway_light_autoclose_timer condition: - condition: state entity_id: input_boolean.hallway_light_auto_close state: "on" - condition: state entity_id: binary_sensor.motion_sensor_158d0001296340 state: "off" action: service: switch.turn_off data: entity_id: group.hallway_lights



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3